package com.shushan.exam.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shushan.shushanbao.R;

/**
 * @ClassName: ReportSelectorsAdapter
 * @Desciption: //问题反馈选项adapter
 * @author: zhangshihao
 * @date: 2018-06-09
 */
public class ReportSelectorsAdapter extends RecyclerView.Adapter<ReportSelectorsAdapter.ViewHolder>{

    private Context mContext;
    private String[] selectorTextes;
    private boolean isNoVideo = false;

    private OnItemClickListener onItemClickListener;

    public ReportSelectorsAdapter(Context context,boolean isNoVideo){
        this.mContext = context;
        this.isNoVideo = isNoVideo;
        if(isNoVideo){
            selectorTextes = mContext.getResources().getStringArray(R.array.question_report_selectors_text_no_video_array);
        }else{
            selectorTextes = mContext.getResources().getStringArray(R.array.question_report_selectors_text_array);
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        this.onItemClickListener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_report_select,null,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tvSelectText.setText(selectorTextes[position]);
        holder.itemView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                holder.itemView.setBackgroundColor(Color.parseColor("#EFEFEF"));
                holder.ivSelectorCircle.setImageResource(R.drawable.ic_blue_circle);
                if(onItemClickListener != null){
                    onItemClickListener.onItemClick(position,isNoVideo);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return selectorTextes.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        private TextView tvSelectText;
        private RelativeLayout rlSelectorsLayout;
        private ImageView ivSelectorCircle;

        public ViewHolder(View itemView) {
            super(itemView);
            tvSelectText = itemView.findViewById(R.id.tv_selector_text);
            rlSelectorsLayout = itemView.findViewById(R.id.rl_selector_layout);
            ivSelectorCircle = itemView.findViewById(R.id.iv_selector_circle);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(int position,boolean isNoVideo);
    }

}
